<template>
  <div class="tabBar">
    <div @click="cAct(0)" :class="active === 0 ? 'active' : ''">
      <i class="iconfont icon-home1"></i>
      <p>首页</p>
    </div>
    <div @click="cAct(1)" :class="active === 1 ? 'active' : ''">
      <i class="iconfont icon-classify"></i>
      <p>分类</p>
    </div>
    <div @click="cAct(2)" :class="active === 2 ? 'active' : ''">
      <i class="iconfont icon-cart-copy"></i>
      <p>购物车</p>
    </div>
    <div @click="cAct(3)" :class="active === 3 ? 'active' : ''">
      <i class="iconfont icon-renwu"></i>
      <p>个人</p>
    </div>
  </div>
</template>

<script>
  export default {
    name: "tabBar",
    data() {
      return {
        active: 0,
      }
    },
    methods: {
      cAct(index) {
        this.active = index
        switch (index) {
          case 0:
            this.$router.push("/main")
            break
          case 1:
            this.$router.push("/classify")
            break
          case 2:
            this.$router.push("/cart")
            break
          default:
            break
        }
      },
    },
    created() {
      switch (this.$route.path) {
        case "/main":
          this.active = 0
          break
        case "/classify":
          this.active = 1
          break
        case "/cart":
          this.active = 2
          break
        default:
          break
      }
    },
  }
</script>

<style lang="scss" scoped>
  .tabBar {
    width: 100%;
    height: 1rem;

    position: fixed;
    z-index: 5;
    background-color: #fff;
    bottom: 0;
    height: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    div {
      flex-basis: 25%;
      height: 100%;
      padding: 5px 0;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      i {
        font-size: 0.32rem;
      }
      p {
        font-size: 0.28rem;
      }
      &.active {
        color: red;
      }
    }
  }
</style>
